// 设置cookie
export function setCookie (cName, value, expiredays) {
  var exdate = new Date()
  exdate.setDate(exdate.getDate() + expiredays)
  document.cookie =
  cName +
    '=' +
    encodeURIComponent(value) +
    ';expires=' +
    exdate.toGMTString() +
    ';path=/'
}
// 读取cookie
export function getCookie (cname) {
  let cstart = null
  let cend = null
  if (document.cookie.length > 0) {
    cstart = document.cookie.indexOf(cname + '=')
    if (cstart !== -1) {
      cstart = cstart + cname.length + 1
      cend = document.cookie.indexOf(';', cstart)
      if (cend === -1) cend = document.cookie.length
      return decodeURIComponent(document.cookie.substring(cstart, cend))
    }
  }
  return ''
}
// 检查cookie
export function checkCookie (cname) {
  const username = getCookie(cname)
  console.log(username)
  if (username != null && username !== '') {
    return true
  } else {
    return false
  }
}
// 清除cookie
export function clearCookie (name) {
  setCookie(name, '', -1)
}
